<?php
class Group extends AppModel
{
    var $name = 'Group';
    var $primaryKey = 'id'; 
    //成员
//   	var $hasAndBelongsToMany = array (
//						'User' => array (
//						'fields' => "username,id",
//						'joinTable' => 'group_users',
//						'foreignKey' => 'group_id',
//						'associationForeignKey' => 'user_id'),
//  					 );
    
  /*  var $hasMany = array(
        'User' => array( 
        'conditions' => array("is_deleted='0'"),
        'fields' => "username,id,isgroupadmin,photo_id",
        'joinTable' => 'users',
//    	'joins'=>array(array(
//                      'table'=>'attachments',
//                      'alias'=>'attachments',
//                      'type'=>'inner',
//    				  'conditions'=> array('users.photo_id = attachments.id'),
//    				)
//    				),
        'foreignKey' => 'group_id',
        'associationForeignKey' => 'id'),
    );*/

//	//获取所有用户
//	function allusers(){
//		$sql="SELECT * FROM `users` order by id";
//		$users=$this->query($sql);
//		return $users;
//	}
    
    //获取group下的用户
    function get_groups_members($groupid){
        $sql="SELECT `user_id` FROM `groups_users` WHERE `group_id` = ' $groupid ' ORDER BY id";
        $users=$this->query($sql);
        return $users;
    }
    //获取所有模块名
    function getGroupList(){
    	$where="Group.is_deleted='0' ";
        $groups=array();
      	$groups=$this->findAll($where,"Group.id,Group.group_name","order by created desc");
        foreach ($groups as $g){
            $grouplist[$g["Group"]["id"]]=$g["Group"]["group_name"];
        }
    	return $grouplist;
    }

}
?>
